{% extends 'base.html' %}
{% load humanize %}
{% block page-content %}
{% include 'nav_cat_bar.html' %}
{% load bootstrap %}

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>{{tip}} </h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <ul class="dropdown-menu dropdown-user">
                            <li><a href="#">Config option 1</a>
                            </li>
                            <li><a href="#">Config option 2</a>
                            </li>
                        </ul>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <div class="row">
                      <div class="col-sm-4 m-b-xs">
                          <button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#idc_add"><i class="icon-cogs"></i>增加</button>
                      </div>
                    </div>
                    {% if error %}
                        <div class="alert alert-warning text-center">{{ error }}</div>
                    {% endif %}
                    {% if add_info %}
                        <div class="alert alert-success text-center">{{ add_info }}</div>
                    {% endif %}
                    <div class="table-responsive">
                        <table class="table table-striped table-bordered table-hover dataTables-example">
                            <thead>
                            <tr>
                                <th class="text-center">密钥名称</th>
                                <th class="text-center">系统用户</th>
                                <th class="text-center">密码</th>
                                <th class="text-center">所属项目</th>
                                <th class="text-center">创建时间</th>
                                <th class="text-center">管理员</th>
                                <th class="text-center">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {% for p in sshkey_info %}
                                  <tr class="text-center">
                                    <td>{{p.name}}</td>
                                    <td>{{p.username}}</td>
                                    <td class="btn_show_td"><a class="btn_show" data-id="{{ p.password }}" type="button">显示</a></td>
                                    <td>{{p.project}}</td>
                                    <td>{{p.create_date|date:"Y-m-d H:i:s"}}</td>
                                    <td>{{p.operator}}</td>
                                    <td>
                                    <a href="{% url 'sshkey_edit' %}?id={{p.id}}"><span class="glyphicon glyphicon-pencil"></span></a>
                                    <a href="{% url 'sshkey_list' %}?id={{p.id}}&action=delete"><span style="color:red" class="glyphicon glyphicon-trash" onclick="return confirm('确认删除吗？')"></span></a>
                                    </td>

                                  </tr>
                                 {% endfor %}
                            </tbody>
                        </table>
                    <!--
                       <div class="col-sm-6">
                            <div class="dataTables_info" id="editable_info" role="status" aria-live="polite">
                                  Showing {{ contacts.start_index }} to {{ contacts.end_index }} of {{ p.count }} entries
                            </div>
                        </div>
                           {% include 'paginator.html' %}
                    -->
                        </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="idc_add" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="exampleModalLabel" align="center">添加SSH密钥</h4>
      </div>
        <div class="modal-body">
            <form id="KeyManagerForm" method="post" class="form-horizontal">
                {{ af.project|bootstrap_horizontal }}
                {{ af.name|bootstrap_horizontal }}
                {{ af.username|bootstrap_horizontal }}
                {{ af.password|bootstrap_horizontal }}
                <p class="col-sm-offset-2 red-fonts">Tips: 项目名简称加 .key</p>
                {{ af.private_key|bootstrap_horizontal }}
                {{ af.public_key|bootstrap_horizontal }}
                {{ af.operator|bootstrap_horizontal }}
            </form>
        </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="submit" class="btn btn-primary" form="KeyManagerForm" formmethod="post" formaction="{% url 'sshkey_list' %}" name="action" value="add">确定</button>
      </div>
    </div>
  </div>
</div>

<link href="/static/css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
<link href="/static/css/plugins/dataTables/dataTables.responsive.css" rel="stylesheet">
<link href="/static/css/plugins/dataTables/dataTables.tableTools.min.css" rel="stylesheet">
    <script src="/static/js/plugins/dataTables/jquery.dataTables.js"></script>
<script src="/static/js/plugins/dataTables/dataTables.bootstrap.js"></script>
<script src="/static/js/plugins/dataTables/dataTables.responsive.js"></script>
<script src="/static/js/plugins/dataTables/dataTables.tableTools.min.js"></script>

<script type="text/javascript">
$(document).ready(function() {
            $('.dataTables-example').dataTable({
                responsive: true,
                "dom": 'T<"clear">lfrtip',
                "iDisplayLength":10,
                "tableTools": {
                    "aButtons":["copy","xls",'print'],
                    "sSwfPath": "/static/js/plugins/dataTables/swf/copy_csv_xls_pdf.swf"
                }
            });
        });


    $(".btn_show").click(function(){

    });

    $(".btn_show_td").click(function(){
            if($(this).find('a').length == 0) {
                var pass = $(this).text();
                console.log(pass);
                $(this).html('<a class="btn_show" data-id="' + pass + '" type="button">显示</a>');
            }else{
                var a = $(this).find('a');
                var pass = a.data('id');
                $(this).text(pass);
            }
        });

</script>

{% endblock %}
